home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMIBEST2.ADF / Best of AMICUS 2 / C / SkinnyC / Listing2full.c < prev    next >
C/C++ Source or Header  |  1987-07-22  |  3KB  |  106 lines

  1. /******************************************************
  2. * REQSTD  - A simple boolean requester command for use
  3. *           within EXECUTE command files.
  4. *******************************************************
  5. * THIS VERSION OBSERVES "STANDARD" C PRGMG CONVENTIONS
  6. *******************************************************
  7. * BVO Computing Services, January 1987, Bob Riemersma
  8. *******************************************************
  9. * Format:   REQSTD <string>
  10. * Template: REQSTD " "
  11. * Purpose:  To ask the user a yes/no question from
  12. *           within an EXECUTE command file.
  13. * Specification:
  14. *   REQSTD invokes a system requester displaying the
  15. *   text argument given, and accepts either a "Yes" or
  16. *   a"No" response via the requester's boolean gadgets.
  17. *   This response is communicated to the command stream
  18. *   via REQSTD's return result: 0 = No, 5 = Yes.
  19. * Example:
  20. *           REQSTD "Are you older than 35?"
  21. *           IF WARN  ;WARN = Yes
  22. *              ECHO "Hmmm, so you are."
  23. *           ELSE
  24. *              ECHO "Just a young whippersnapper!"
  25. *           ENDIF
  26. *******************************************************
  27. * Note to rodent-haters:
  28. *   Beginning with KS/WB 1.2 you may respond using
  29. *   "Left Amiga-V" for "Yes", "Left Amiga-B" for "No".
  30. ******************************************************/
  31. #include <exec/types.h>
  32. #include <libraries/dosextens.h>
  33. #include <intuition/intuition.h>
  34. struct IntuitionBase *IntuitionBase;
  35. #define INTUITION_REV 0
  36.  
  37. struct IntuiText Question =
  38. {
  39.    2, 1,          /* FrontPen, BackPen */
  40.    JAM1,
  41.    8, 6,          /* LeftEdge, TopEdge */
  42.    NULL,          /* Use default font */
  43.    NULL,          /* IText, filled at runtime */
  44.    NULL           /* No linked IntuiTexts */
  45. },
  46.                  Positive =
  47. {
  48.    2, 1,
  49.    JAM1,
  50.    6, 4,
  51.    NULL,
  52.    "Yes",
  53.    NULL
  54. },
  55.                  Negative =
  56. {
  57.    2, 1,
  58.    JAM1,
  59.    6, 4,
  60.    NULL,
  61.    "No",
  62.    NULL
  63. };
  64.  
  65. #define Me 0
  66. extern struct Process *FindTask();
  67. struct Process *Myself;
  68.  
  69. extern BOOL AutoRequest();
  70.  
  71. main(argc, argv)
  72.    int argc;
  73.    UBYTE *argv[];
  74. {
  75.    int QuestionChars,
  76.        ReqWidth;
  77.    BOOL Yes;
  78.  
  79.    if (argc != 2)
  80.       exit(120);
  81.  
  82.    Question.IText = argv[1];
  83.  
  84.    /* Count # chars in argument string */
  85.    QuestionChars = 0;
  86.    while (*argv[1]++ != '\0')
  87.       QuestionChars++;
  88.  
  89.    IntuitionBase = (struct IntuitionBase *)
  90.                    OpenLibrary("intuition.library", INTUITION_REV);
  91.    if (IntuitionBase == NULL)
  92.       exit(FALSE);
  93.  
  94.    Myself = FindTask(Me);
  95.  
  96.    if ((ReqWidth = 8*QuestionChars+40) < 200)
  97.       ReqWidth = 200;
  98.    Yes = AutoRequest(Myself->pr_WindowPtr,            /* Console Window */
  99.                      &Question, &Positive, &Negative, /* IntuiTexts */
  100.                      NULL, NULL,                      /* No extern. events */
  101.                      ReqWidth, 50);                   /* Width, Height */
  102.  
  103.    CloseLibrary(IntuitionBase);
  104.    exit((Yes) ? 5 : 0);
  105. }
  106.